package com.msl.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;

import com.msl.R;
import com.msl.tool.ToastUtils;

import java.lang.reflect.Method;


public class NumDialog extends Dialog {

    private String tag = "NumDialog";

    public interface PriorityListener {
        /**
         * 回调函数，用于在Dialog的监听事件触发后刷新Activity的UI显示
         */
        void setActivityText(String string);
    }
    private PriorityListener listener;

    private Context mContext;
    private Button bt1, bt2;
    private EditText ed;


    public NumDialog(final Context context, int theme , PriorityListener priorityListener) {
        super(context, theme);
        mContext = context;
        listener = priorityListener;
        setContentView(R.layout.dialog_num);
        ed = (EditText) findViewById(R.id.ed);

//        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
//        try {
//            Class<EditText> cls = EditText.class;
//            Method setShowSoftInputOnFocus;
//            setShowSoftInputOnFocus = cls.getMethod("setShowSoftInputOnFocus",
//                    boolean.class);
//            setShowSoftInputOnFocus.setAccessible(true);
//            setShowSoftInputOnFocus.invoke(ed, false);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }


        bt1 = (Button) findViewById(R.id.bt1);
        bt2 = (Button) findViewById(R.id.bt2);
        bt2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
        bt1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(ed.getText().toString().length()==0)
                {
                    ToastUtils.showSingleToast(context,"请填写数量");
                    return;
                }
                listener.setActivityText(ed.getText().toString());
                dismiss();
            }
        });
    }


}


